/**
 * Copyright (c) 2010 David Hamrick, Guy Kopsombut, Emily Ross 
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
#import "TestPassenger.h"

#import "Passenger.h"

@implementation TestPassenger

- (void)testCreatePassenger
{
	Passenger* p = [[Passenger alloc] init];
	[p setName:@"Bob"];
	[p setAddress:@"blah street"];
	[p setPhone:@"555-555-5555"];
	[p save];
	STAssertTrue([p ID] != 0,@"ID should not be 0");
	[p release];
}

- (void)testDeleteAll
{
	Passenger* p = [[Passenger alloc] init];
	[p setName:@"Bob"];
	[p setAddress:@"blah street"];
	[p setPhone:@"555-555-5555"];
	[p save];
	
	[Passenger deleteAll];
	NSArray* array = [Passenger allPassengers];
	NSLog(@"array = %@",array);
	STAssertNotNil(array,@"Array should not be nil");
	STAssertTrue([array count]==0,@"There should be no passengers");
}

- (void)testGetAll
{
	[self testDeleteAll];
	[self testCreatePassenger];
	[self testCreatePassenger];	
	[self testCreatePassenger];
	NSArray* passengerList = [Passenger allPassengers];
	STAssertTrue([passengerList count]==3,@"There should be 3 cabs");
}

- (void)testGetById
{
	Passenger* p = [[Passenger alloc] init];
	[p setName:@"Bob"];
	[p setAddress:@"blah street"];
	[p setPhone:@"555-555-5555"];
	[p save];
	NSLog(@"[p ID] = %d",[p ID]);
	Passenger* p2 = [Passenger PassengerWithId:[p ID]];
	STAssertTrue([p2 ID] == [p ID],@"ID doesn't Match");
	STAssertTrue([[p2 name] isEqualToString:[p name]],@"Name doesn't match");
}

- (void)testDoubleSave
{
	[Passenger deleteAll];
	Passenger* p = [[Passenger alloc] init];
	[p setName:@"Tom"];
	[p setAddress:@"123 blah street"];
	[p setPhone:@"555-555-5555"];
	[p save];
	NSArray* passengerList = [Passenger allPassengers];
	STAssertTrue([passengerList count] == 1,@"There should be 1 cab");
	[p save];
	STAssertTrue([passengerList count] == 1,@"There shouldn't be 2 cabs");
}

- (void)testUpdate
{
	[Passenger deleteAll];
	Passenger* p = [[Passenger alloc] init];
	[p setName:@"Tom"];
	[p setAddress:@"123 blah street"];
	[p setPhone:@"555-555-5555"];
	[p save];
	[p setName:@"Bill"];
	[p save];
	NSLog(@"Name = %@",[p name]);
	STAssertTrue([[p name] isEqualToString:@"Bill" ],@"The passenger's name should have updated");
}

- (void)testDelete
{
	[Passenger deleteAll];
	Passenger* p = [[Passenger alloc] init];
	[p setName:@"Tom"];
	[p setAddress:@"123 blah street"];
	[p setPhone:@"555-555-5555"];
	[p save];
	NSArray* passengerList = [Passenger allPassengers];
	STAssertTrue([passengerList count] == 1,@"Passenger list should only have 1 passenger");
	[p delete];
	passengerList = [Passenger allPassengers];
	STAssertTrue([passengerList count] == 0,@"Passenger list should be empty");
}

@end
